package com.xfhy.wallpaperdemo.live;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.xfhy.wallpaperdemo.DaemonLog;
import com.xfhy.wallpaperdemo.RomUtil;
import com.xfhy.wallpaperdemo.account.AccountHelper;
import com.xfhy.wallpaperdemo.screenmonitor.ScreenMonitorHelper;

public class DaemonReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        DaemonLog.d("DaemonReceiver action=" + action);
        if (action != null) {
            char c = 65535;
            switch (action.hashCode()) {
                case -2128145023:
                    if (action.equals("android.intent.action.SCREEN_OFF")) {
                        c = 1;
                        break;
                    }
                    break;
                case -1454123155:
                    if (action.equals("android.intent.action.SCREEN_ON")) {
                        c = 2;
                        break;
                    }
                    break;
                case 823795052:
                    if (action.equals("android.intent.action.USER_PRESENT")) {
                        c = 3;
                        break;
                    }
                    break;
                case 1947666138:
                    if (action.equals("android.intent.action.ACTION_SHUTDOWN")) {
                        c = 0;
                        break;
                    }
                    break;
                default:
                    break;
            }
            if (c == 0) {
                AccountHelper.reSync(context);
            } else if (c != 1) {
                if (c == 2) {
                    ScreenMonitorHelper.resume();
                }
            } else if (!RomUtil.isOppo()) {
                ScreenMonitorHelper.pause();
            }
        }
    }
}
